<?php

namespace app\common\model\mysql;

use think\Model;

class SOrderRefund extends Model
{
    /**
     * 查询售后订单数据列表
     * @param $where
     * @param $field
     * @param $limit
     * @param $page
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getNormalOrderRefundList($where, $field,$limit,$page){
        $order = [
            "a.order_refund_id" =>"desc",
        ];
        $result = $this->alias('a')->join('s_order b', 'a.order_id = b.order_id')->where($where)->field($field)->order($order)
            ->paginate([
                'list_rows' => $limit,
                'page' => $page,
            ]);
        return $result;
    }

    /**
     * 根据id获取售后订单信息
     * @param $id
     * @param string $field
     * @return false
     */
    public function getOrderRefundIdData($id, string $field = "*"){
        if(empty($id)){
            return false;
        }
        $where = [
            "a.order_refund_id" =>$id,
        ];
        $result = $this->alias('a')->join('s_order b', 'a.order_id = b.order_id')->where($where)->field($field)->find();
        return $result;
    }

    /**
     * 根据$orderId查找售后订单数据
     * @param $orderId
     * @param string $field
     * @return SOrderRefund|array|false|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getRefundOrderByIdFind($orderId, string $field = '*'){
        if(empty($orderId)){
            return false;
        }
        $where = [
            "order_id" =>$orderId,
        ];
        $result = $this->where($where)->field($field)->find();
        return $result;
    }
}
